#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>


//孤儿进程
int main()
{
  printf("I am running ...\n");
  pid_t id = fork();

  if(id == 0)//child
  {
    int count = 5;
    while(1)
    {
      printf("I am child ...PID:%d, PPID:%d\n", getppid(), getppid());
      sleep(1);
    }
  }
  else if(id >= 0)//father
  {
    int count = 5;
    while(count)
    {
      printf("I am father...PID:%d, PPID:%d, count:%d\n", getpid(), getppid(),count);
      sleep(1);
      --count;
    }
    printf("father quit...\n");
    exit(0);
  }
  else
  {
  printf("错误进程\n");
  }

  return 0;
}
